package com.bulemobi.activity.ac_userCentre_Setting;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.bulemobi.data.DataCentre;
import com.bulemobi.net.tsz.afinal.FinalHttp;
import com.bulemobi.net.tsz.afinal.annotation.view.ViewInject;
import com.bulemobi.net.tsz.afinal.http.AjaxCallBack;
import com.bulemobi.net.tsz.afinal.http.AjaxParams;
import com.bulemobi.urlCentre.UrlCentre;
import com.bulemobi.view.BaseActivity;
import com.bulemobi.view.titleView.ActionBarView;
import com.jsyh.hcb.R;

/**
 * Created by 武 on 2014/9/22 0022.
 * 修改登陆密码
 */
public class Ac_Change_LoginPw extends BaseActivity implements View.OnClickListener {
    @ViewInject(id = R.id.actionBar)
    ActionBarView actionBarView;
    @ViewInject(id = R.id.tv_confirm)
    TextView tv_confirm;
    @ViewInject(id = R.id.ed_oldPw)
    EditText ed_oldPw;
    @ViewInject(id = R.id.ed_newPw)
    EditText ed_newPw;
    @ViewInject(id = R.id.ed_newPwAgain)
    EditText ed_newPwAgain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_chang_login_pw);
        initView();
    }

    private void initView() {
        actionBarView.title.setText("修改密码");
        tv_confirm.setOnClickListener(this);
    }

    private void requestHttp(String url, AjaxParams params) {
        FinalHttp http = new FinalHttp();
        http.post(url, params, new AjaxCallBack<Object>() {
            @Override
            public void onStart() {
                showProgressDialog();
                super.onStart();
            }

            @Override
            public void onSuccess(Object o) {
                closeProgressDialog();
                Log.d("OnSuccess", o.toString());
                super.onSuccess(o);
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                closeProgressDialog();
                super.onFailure(t, errorNo, strMsg);
            }
        });
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == tv_confirm.getId()) {
            String oldPw = ed_oldPw.getText().toString();
            String newPw = ed_newPw.getText().toString();
            String newPwAgain = ed_newPwAgain.getText().toString();
            AjaxParams params = new AjaxParams();
            params.put("modifyFlag", DataCentre.MODIFYFLAG);
            params.put("Password", oldPw);
            params.put("PasswordConfirm", newPw);
            params.put("confirmPassword", newPwAgain);
            params.put("TerminalType", UrlCentre.TerminalType);
            params.put("UserType", UrlCentre.UserType);
            params.put("ChannelId", UrlCentre.ChannelId);
            requestHttp(UrlCentre.ModifyUserInfo, params);
        }
    }
}
